package com.qf.service;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsBrandMapper;
import com.qf.pojo.DtsBrand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * projectName: shop-manage
 *
 * @author: 元
 * time: 2021/9/15 0015 20:54
 * description:品质制造商实现类
 */
@Service
public class BrandServiceImpl implements BrandService{

    @Autowired
    private DtsBrandMapper dtsBrandMapper;


    @Override
    public IPage<DtsBrand> findByPage(Integer page, Integer limit,Integer id,String name, String sort, String order) {

        //分页参数
        Page<DtsBrand> brandPage = new Page<>(page,limit);
        //查询数据
        QueryWrapper<DtsBrand> queryWrapper = new QueryWrapper<>();
        if (id !=null){
            queryWrapper.like("id",id);
        }
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name",name);
        }
        if ("asc".equalsIgnoreCase(order)){
            queryWrapper.orderByAsc(sort);
        }else{
            queryWrapper.orderByAsc(sort);
        }
        IPage<DtsBrand> pageResult = dtsBrandMapper.selectPage(brandPage,queryWrapper);
        return pageResult;
    }

    @Override
    public int updateBrand(DtsBrand dtsBrand) {
        dtsBrand.setUpdateTime(new Date());
        int count = dtsBrandMapper.updateById(dtsBrand);
        return count;
    }

    @Override
    public int deleteById(Integer id) {
        int count = dtsBrandMapper.deleteById(id);
        return count;
    }

    @Override
    public DtsBrand addBrand(DtsBrand dtsBrand) {
        dtsBrand.setAddTime(new Date());
        dtsBrandMapper.insert(dtsBrand);
        return dtsBrand;
    }


}
